#include "Enemy.h"
#include "Factory.h"
#include "File.h"
#include "DX11ErrorReport.h"
#include "ObjMeshManager.h"
#include "AntTweakBarManager.h"

Enemy::Enemy()
{
	//m_addVel = true;
	//m_vel = 0.001f;
	m_collided = false;
	//m_rbSquare->SetRadius(2.0f);
}


void Enemy::Draw()
{
	//m_rbSquare->Draw();

	//static float rotAngle = 0.0f;
	//rotAngle += 0.001f;
	////m_oobb3.Rotate(0, Vec3f(0, 0, 0));
	//m_oobb3.centre.x = XMVectorGetX(m_rbSquare->GetPosition());
	//m_oobb3.centre.y = XMVectorGetY(m_rbSquare->GetPosition());
	//m_oobb3.centre.z = XMVectorGetZ(m_rbSquare->GetPosition());
	//
	////BoxPoints3 bp;
	////CalculateOOBBCorners(m_oobb3, bp);
	////
	////for (int i = 0; i != 8; i++)
	////{	
	////	TheObjMeshManager::Instance()->Translate("crate_textured", bp.corners[i].x, bp.corners[i].y, bp.corners[i].z);
	////	//TheObjMeshManager::Instance()->Rotate("crate_textured", 0, 0, 0, 0);
	////	TheObjMeshManager::Instance()->Scale("crate_textured", 0.5f, 0.5f, 0.5f);
	////	TheObjMeshManager::Instance()->Draw("crate_textured");
	////}
	//
	//if (m_collided)
	//{
	//	TheObjMeshManager::Instance()->ChangeShader("crate_textured", "lightbulb_1");
	//	TheObjMeshManager::Instance()->SetColour("crate_textured", D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f));
	//}
	//else
	//{
	//	TheObjMeshManager::Instance()->SetColour("crate_textured", D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f));
	//}

	//TheObjMeshManager::Instance()->Translate("crate_textured", m_oobb3.centre.x, m_oobb3.centre.y, m_oobb3.centre.z);
	////TheObjMeshManager::Instance()->Rotate("crate_textured", 0, 0, 1, 0);
	//TheObjMeshManager::Instance()->Scale("crate_textured", m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2);
	//TheObjMeshManager::Instance()->Draw("crate_textured");
	////m_size = 1;

	////if (m_collided)
	////{
	////	TheObjMeshManager::Instance()->ChangeShader("sphere", "lightbulb_1");
	////	TheObjMeshManager::Instance()->SetColour("sphere", D3DXVECTOR4(1.0f, 0.0f, 0.0f, 1.0f));
	////}
	////else
	////{
	////	TheObjMeshManager::Instance()->SetColour("sphere", D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f));
	////}

	////TheObjMeshManager::Instance()->Translate("sphere", m_rbSphere->GetPosition());
	////TheObjMeshManager::Instance()->Scale("sphere", 
	////												m_rbSphere->GetRadius(), 
	////												m_rbSphere->GetRadius(), 
	////												m_rbSphere->GetRadius());
	////TheObjMeshManager::Instance()->Draw("sphere");

	//m_collided = false;	
	TheObjMeshManager::Instance()->Translate("crate_textured", m_pos);
	TheObjMeshManager::Instance()->Rotate("crate_textured", DegToRad(0), 0, 1, 1);
	TheObjMeshManager::Instance()->Scale("crate_textured", m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2);
	TheObjMeshManager::Instance()->Draw("crate_textured");
}

void Enemy::Update()
{

}

void Enemy::StopAddingVel()
{
	m_collided = true;
	//m_size = 4;
}


bool Enemy::Load(File* f)
{
	if (!f->GetD3DXVECTOR3(&m_pos))
	{
		DX11ErrorMsg(L"Expected position", L"Enemy load function error", MB_YESNO);
	}

	if (!f->GetOOBB3(&m_oobb3))
	{
		DX11ErrorMsg(L"Expected oobb2", L"Enemy load function error", MB_YESNO);
	}

	return true;
}

// load Enemy as game object functions
GameObject* CreateEnemy()
{
	return new Enemy();
}

static bool b = TheGameObjectFactory::Instance()->AddType("Enemy", CreateEnemy);

const char* Enemy::GetTypeName() const
{
	return "Enemy";
}